﻿package net.wangit.jdbc.type;

import net.wangit.Row;
import net.wangit.jdbc.database.Database;
import net.wangit.util.StringUtil;

public abstract class PrecisionType extends AbstractType {

	private static final long serialVersionUID = 1L;
	private static final String PRECISION_PLACEHOLDER = "$p";
	protected int precision;

	public PrecisionType(Row row) {
		precision = row.getInt("l", 50);
	}

	public String getSqlTypeName(Database database) {
		String sqlTypeName = super.getSqlTypeName(database);
		return dealwithPresision(sqlTypeName);
	}

	private String dealwithPresision(String sqlTypeName) {
		return StringUtil.replace(sqlTypeName,
				PrecisionType.PRECISION_PLACEHOLDER, Integer
						.toString(precision));
	}
}
